require("../util.js");
require("../component/components.js");
// require("../component/purchaseHeader.js");
// require("../component/footer.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#bursting",
    data:{
        pageNumber:1,
        burstALL:{},
        burstALLList:{},
        burstALLList1:[],
        burstALLList2:[],
        hours:"",//时
        minutes:"",//分
        seconds:"",//秒
        endSecond:"",
        startsecond:"",
        num:""
    },
    mounted:function(){
        this.getLuckyBurstALLList();
    },
    methods: {
        //后退
        getBack: function () {
            history.go(-1);
        },
        bgimg: function (url) {
            url = url ? url : "";
            return {
                "background-image": 'url("' + url + '"),url("")'
            }
        },
        //乐购爆款列表
        getLuckyBurstALLList: function () {
            var that = this;
            this.ajax({
                url: "/purchase/getLuckyBurstALLList",data: {pageNumber: that.pageNumber},dataType: "json",method: "post"}, function (b) {
                if (b.json.code == 0 && b.json.data) {
                    that.burstALL = b.json.data;
                    that.burstALLList = that.burstALL.records;
                    that.burstALLList1 = that.burstALLList.list;
                    if (that.burstALLList.pageNumber > 1) {
                        if (that.burstALLList.list.length > 0) {
                            that.burstALLList2 = that.burstALLList2.concat(b.json.data.list);
                        }
                    } else {
                        that.burstALLList2 = that.burstALLList1;
                    }
                    console.log(that.burstALLList)
                    // console.log(that.discountsList2);
                    that.num=that.burstALLList1[0].users.length;
                    that.endDate = that.burstALL.endDate;
                    that.endSecond = parseInt(that.endDate) * 60 * 60;
                    that.compareDate();
                    vm.loadFlag = false;
                    lazyload();
                } else {
                    that.burstALL = {};
                    that.burstALLList = {};
                    that.burstALLList1 = [];
                    that.burstALLList2 = [];
                    vm.$refs.prompt.toast("获取爆款列表失败！")
                }
            });
        },
        compareDate: function () {
            a = setInterval(this.leftTimer, 1000);
            //this.leftTimer();
        },
        //时分秒倒计时
        leftTimer: function () {
            var that = this;
            var date = new Date();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            this.startsecond = (hour * 60 + minute) * 60 + second;
            if (that.endSecond > that.startsecond) {
                that.hours = Math.floor((that.endSecond - that.startsecond) / 60 / 60);
                that.minutes = Math.floor((that.endSecond - that.startsecond) / 60 % 60);
                that.seconds = Math.floor((that.endSecond - that.startsecond) % 60);
                that.hours = checkTime(that.hours);
                that.minutes = checkTime(that.minutes);
                that.seconds = checkTime(that.seconds);
            } else {
                clearInterval(a);
            }
        },
        getNext:function(item){
            console.log(item);
            location.href="/purchase/goodsDetails?type=4&productId="+item.productId;
        }
    }
    ,watch:{
        num:function(){
            this.$nextTick(function(){
                console.log($(".secondKill-snatchCent .swiper-slide").length);
                var swiper = new Swiper('.swiper-container', {
                    slidesPerView: "auto",
                    spaceBetween: 5,
                    loop : true,
                    autoplay:true,
                    observer:true,//修改swiper自己或子元素时，自动初始化swiper
                    observeParents:true//修改swiper的父元素时，自动初始化swiper
                });
            });
        }
    }
});
var a;
function checkTime(i){ //将0-9的数字前面加上0，例1变为01
    if(i<10){
        i = "0" + i;
    }
    return i;
}
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
var loadFlag;
window.onscroll=function(){
    // if(getDocumentTop()>739){
    //     vm.isNav=2;
    // }else{
    //     vm.isNav=1;
    // }
    loadFlag = vm.burstALLList.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.data.pageNumber++;
            vm.getLuckyBurstALLList();
            lazyload();
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};
function lazyload(){
    $("img.lazy").lazyload();
}